//
//  TestBatchLogin.swift
//  LeGou
//
//  Created by lxm on 2022/11/17.
//

import UIKit

class TestBatchLogin: ZMViewController, UITableViewDelegate, UITableViewDataSource {
    //MARK: --------------------属性--------------------
    
    //MARK: --------------------UI控件--------------------
    @IBOutlet weak var textView: UITextView!
    
    @IBOutlet weak var tableView: UITableView!
    //MARK: --------------------生命周期--------------------
    override func viewDidLoad() {
        super.viewDidLoad()
        setUI()
        addConstraints()
        bindAction()
    }
    //MARK: --------------------UI--------------------
    func setUI() {
        title = ""
        tableView.delegate = self
        tableView.dataSource = self
    }
    
    func addConstraints() {
        
    }
    
    //MARK: --------------------methods--------------------
    func bindAction() {
        
    }

    @IBAction func onLogin(_ sender: Any) {
//        let pre = "183804420"
//        var phones = [String]()
//
//        var sql = ""
//        for i in 0 ..< 20 {
//            let p = pre + "\(String(format: "%02d", i))"
//            phones.append(p)
//            sql.append("'\(p)',")
//        }
//        TestService.shared.phoneArray = phones
//        TestService.shared.autoRegister()
//
//
//
//        XMLogger.info("sql is :" + "UPDATE eb_user_bank SET mall_money = 1000000, money = 1000000 WHERE id IN (SELECT uid FROM eb_user WHERE phone IN (\(sql))")
        
        let sub =  textView.text.split(separator: ",")
        var accountsArray : [(String, String)] = [(String, String)]()
        for s in sub {
            let ss = s.split(separator: "@")
            if ss.count == 2 {
                accountsArray.append(("\(ss[0])", "\(ss[1])"))
            }
        }
        TestService.shared.accountsArray = accountsArray
        TestService.shared.login {
            self.tableView.reloadData()
        }
    }
    
    @IBAction func onAuction(_ sender: Any) {
        let v = UserAuctionIndex()
        self.navigationController?.pushViewController(v, animated: true)
    }
    
    //MARK: --------------------delegate--------------------
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return TestService.shared.players.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: "cell")
        if cell == nil {
            cell = UITableViewCell.init(style: .default, reuseIdentifier: "cell")
        }
        let data = TestService.shared.players[indexPath.row]
        
        cell?.textLabel?.text = "\(data.model.phone)____\(data.model.nikeName)"
        
        return cell!
    }
    
}
